<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .wrap {
            width: 300px;
            background: #96176e;
            transition: all .4s;
            height: 200px;
        }
        .wrap div {
            height: 200px;
        }
        .box2 {
            display: none;
        }
        .show {
            display: block;
        }
    </style>
</head>
<body>
<button id="btn">开始</button>
<div class="wrap">
    <div class="box1"></div>
    <div  class="box2"></div>
</div>
<script>
  // 兼容行好，就是需要写点js代码
    const btn = document.querySelector("#btn");
    const box2 = document.querySelector(".box2");
    const wrap = document.querySelector(".wrap");
    let isExpand = false;

    btn.onclick = function () {
      isExpand = !isExpand;
      let box2Rect;

      if (isExpand) {
        box2.classList.toggle("show");
        box2Rect = box2.getBoundingClientRect();
      } else {
        box2Rect = box2.getBoundingClientRect();
        box2.classList.toggle("show");
      }
      const boxHeight = box2Rect.height;

      wrap.style.height = wrap.clientHeight + (isExpand ? boxHeight : -boxHeight) + 'px';
    }
</script>
</body>
</html>